home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-06-04 | 16.5 KB | 485 lines | [TEXT/MPS ] |
- #
- # File: ResEditTest.vu
- #
- # Contains: A ResEdit test script that creates a window for each of the predefined resource types.
- # If you have a file called "vu-wants-1-of-each" on the topmost volume, this script
- # will delete it and recreate it. This name is kept in a string called gResFileName
- # and can be changed if desired.
- #
- # This script does quite a bit so it takes a while to execute. If you would rather
- # have it create some number of resource type windows less than the total, modify the
- # value of numberOfResourcesToMake. The following statement will create the
- # first 15 resource types:
- # numberOfResourcesToMake := 15;
- # The variable numberOfResourcesToMake is used to pass a second parameter to
- # CreateOneOfEachType() which indicates the number of resource types you'd
- # like created.
- #
- # This script demonstrates how to use the scroll command to scroll through a
- # scrolling list of items. Run it and watch what it does with scrolling.
- #
- # Libraries: "UtilityTasks.vulib"
- #
- # Prerequisites:
- # Be sure the UtilityTasks.vulib library is available.
- # The Finder must be the active app.(preferably the only app. running).
- # If the target is running under a 6.0.x system, then:
- # The ResEdit app must be in the root directory as the first file listed
- # (view by name and rename to start its name with 'aa' for example).
- # Either this window should be open and no other;
- # or the volume icon selected and no windows open.
- # If the target is running under a 7.0.x system, then:
- # The ResEdit app must be the first occurance of ResEdit which Finder's
- # Find command will select. This is best accomplished by putting it in the
- # frontmost window and removing any other files with 'ResEdit' in it's name.
- #
- # Written by: Jay Jessen and Rick Violet
- #
- # Copyright: © 1990-1992 by Apple Computer, Inc., all rights reserved.
- #
- # Change History:
- #
- # 7/21/92 DGG Made main body into script.
- # 7/7/92 DGG Revamped variable names.
- # 6/18/92 DGG Added handling for Sys6 "replace" dialog.
- # 1/9/91 Rick Moved some Tasks to "UtilityTasksLib.vu"
- # 1/4/91 naga Modified the header comments
- # 1/2/91 Rick Updated Jay's version so that this script will run against both
- # ResEdit v1.2 and ResEdit v2.1 (under system 6.0x and system 7.0).
- # In the process defined some new tasks modified some old tasks and
- # task names
- # 6/7/89 Jay Created from an old version (optimized scrolling actions)
- #
- # To Do:
- #
-
- Libraries "UtilityTasks.vulib";
-
- (************************************************************************************
- * Task SetScreenDependents()
- ************************************************************************************)
- task SetScreenDependents()
- begin
- # Where to drag resource windows to get them out of the way
- global Wind_x := 250; # hardwired for now
- global Wind_y := 20; # hardwired for now
- end;
-
- (************************************************************************************
- * Task ClearFile(fileToClear,checkSelection := true)
- * clears a file from Volume window,
- * if checkSelection is false it'll clear the current selection ( For ResEdit 1.2 )
- ************************************************************************************)
- task ClearFile(fileToClear,checkSelection := true)
- begin
- global gVolumeName;
-
- if (not match[window t:gVolumeName o:1]!)
- select [window t:gVolumeName]!;
- if (checkSelection)
- begin
- type k:{ "v" };
- foundIt := false;
- while (not foundIt)
- begin
- UseKeyboardEquivalent("o");
- if (match [staticText t:/The file≈has no resource fork≈Do you wish≈it ∂?/
- w:[window o:1 s:dialog]]!)
- begin
- select [button t:'Cancel']!;
- type k:{ downarrowKey };
- end;
- else
- begin
- if (((match [window o:1]!).t) = fileToClear)
- begin
- foundIt := true;
- close [window o:1]!;
- end;
- else
- begin
- close [window o:1]!;
- type k:{ downarrowKey };
- end;
- end;
- end;
- end;
- select [menuItem t:'Clear' m:'Edit']!;
- if (match [button t:'OK']! and match[button t:'Cancel']!)
- select [button t:'OK'];
- end;
-
- (************************************************************************************
- * Task CreateResourceFile(gResFileName)
- * Creates a resource file of name gResFileName.
- * Replaces any previously existing file of that name. ( For ResEdit 1.2 )
- ************************************************************************************)
- task CreateResourceFile(gResFileName)
- begin
- global gVolumeName;
-
- if(not match[window t:gVolumeName o:1]!)
- select [window t:gVolumeName]!;
- select [menuItem title:'New' m:'File']!;
- type k:{ gResFileName };
- select [button title:'OK']!;
- if(match[button t:'OK' w:[window o:1]]!)
- begin
- select [button t:'OK']!;
- select [button t:'Cancel']!;
- ClearFile(gResFileName);
- select [menuItem title:'New' m:'File']!;
- type k:{ gResFileName };
- select [button title:'OK']!;
- end;
- end;
-
- (************************************************************************************
- * Task CreateResourceFile2(gResFileName)
- * Creates a resource file of name gResFileName.
- * Replaces any previously existing file of that name. ( For ResEdit 2.1 )
- ************************************************************************************)
- task CreateResourceFile2(gResFileName) begin
-
- global gVolumeName;
-
- wait(2);
-
- if( not match [window] )
- select [menuItem title:/New≈/ m:'File']!;
- else if (match [button t:"New" ]! and match [button t:"Open"]!)
- select [ button t:"New" ];
-
- wait(2);
-
- type k:{ gResFileName };
- select [button title:'New']!;
-
- wait(2);
- if (match [staticText t:?dialogText w:[window o:1 s:dialog]]!)
- begin
- if (dialogText ~= /Replace≈/)
- begin
- if (match [button t:'Replace'])
- select [button t:'Replace']!;
- else if (match [button t:'Yes'])
- select [button t:'Yes']!;
- end;
- end;
- end;
-
- (************************************************************************************
- * Task SetScrollBarGlobals()
- * set global values for scroll bar in "Select New Type" dialog ( For ResEdit 1.2 )
- ************************************************************************************)
- task SetScrollBarGlobals()
- begin
-
- global gScrollbarLeft,gScrollbarTop,gScrollbarRight,gScrollbarBottom;
- global gPreviousScrollerSetting;
-
- select [menuItem title:/New≈/ m:'File']!;
-
- # get the "select new type" dialog's bounding rect and put it in windowRect
- match [window o:1 r:?windowRect]!;
-
- # get the scroll bar's current setting and rectangle (in local coords)
- currentScroller := match [scrollBar windowOwner:[window o:1]
- s:?controlValue r:?scrollerRect]!;
-
- # ~~~~~ compute scroll bar rect in global coordinates (8 compensate for the dialog border pixels)
- gScrollbarLeft := scrollerRect[1];
- gScrollbarTop := scrollerRect[2];
- gScrollbarRight := scrollerRect[3];
- gScrollbarBottom := scrollerRect[4];
-
- if(controlValue[1] = controlValue[2])
- global gDoneScrolling := true;
- else
- gPreviousScrollerSetting := controlValue;
- end;
-
- (************************************************************************************
- * Task SetScrollBarGlobals2()
- * set global values for scroll bar in "Select New Type" dialog ( For ResEdit 2.1 )
- ************************************************************************************)
- task SetScrollBarGlobals2()
- begin
- global gScrollbarLeft,gScrollbarTop,gScrollbarRight,gScrollbarBottom;
- global gPreviousScrollerSetting;
-
- select [menuItem title:/Create New Resource/ m:'Resource']!;
-
- # get the "select new type" dialog's bounding rect and put it in windowRect
- match [window ord:1 rect:?windowRect]!;
-
- # get the scroll bar's current setting and rectangle (in local coords)
- currentScroller := match [scrollBar windowOwner:[window o:1]
- s:?controlValue r:?scrollerRect]!;
-
- # ~~~~~ compute scroll bar rect in global coordinates (8 compensate for the dialog border pixels)
- gScrollbarLeft := scrollerRect[1];
- gScrollbarTop := scrollerRect[2];
- gScrollbarRight := scrollerRect[3];
- gScrollbarBottom := scrollerRect[4];
-
- if(controlValue[1] = controlValue[2])
- global gDoneScrolling := true;
- else
- gPreviousScrollerSetting := controlValue;
- end;
-
- (************************************************************************************
- * Task PositionResTypeWindow()
- * Position the resource type window, away from the volume window ( For ResEdit 1.2 )
- ************************************************************************************)
- task PositionResTypeWindow()
- begin
- drag [window ord:1] a:{ global Wind_x,global Wind_y };
- Wind_x := Wind_x + 1;
- Wind_y := Wind_y + 2;
- end;
-
- (************************************************************************************
- * Task SelectNextType()
- * scrolls to the next resource type in the "Select New Type" dialog
- ************************************************************************************)
- task SelectNextType()
- begin
- global gPreviousScrollerSetting,clicksForCurrentValue;
- global gDoneScrolling;
- global listItemHeight;
- global gScrollbarLeft,gScrollbarTop,gScrollbarRight,gScrollbarBottom;
- global gNonTopItemSelection;
-
- scroll [scrollBar w:[window o:1]] a: gPreviousScrollerSetting;
- if(gDoneScrolling) begin # ~~ only need to select the remaining visible items (no more scrolling)
- move a:{ gScrollbarLeft - 10,
- gScrollbarTop + ((gNonTopItemSelection - 1) * listItemHeight) + 5 };
- gNonTopItemSelection := gNonTopItemSelection + 1;
- end;
- else
- begin
- move a:{ gScrollbarRight - 5,gScrollbarBottom - 5 };
- click;
- match [scrollBar w:[window ord:1] setting:?controlValue]!;
- if(controlValue[1] = gPreviousScrollerSetting[1])
- begin # ~~~~~~~ scroll value hasn't changed
- clicksForCurrentValue := clicksForCurrentValue + 1;
- for i := 1 to clicksForCurrentValue click;
- end;
- else
- clicksForCurrentValue := 0;
- move a:{ gScrollbarLeft - 10,gScrollbarTop + 5 };
- end;
- click;# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ make the new selection
- if (not gDoneScrolling) begin
- match [scrollBar w:[window ord:1] setting:?controlValue]!;
- gPreviousScrollerSetting := controlValue;
- if (controlValue[1] = controlValue[2]) begin
- gDoneScrolling := true;
- listItemHeight :=
- (gScrollbarBottom - gScrollbarTop) / 7;# ~~~~~~~~~~~~~~~ 7 is the number of visible types
- gNonTopItemSelection := 2;# ~~~~~~~~~~~~~~~~~~~~ now used to select remaining visible items
- end;
- end;
- end;
-
- (************************************************************************************
- * Task CheckForAlertOrPositionWindow()
- * checks for an alert and if one isn't there positions the window,
- * else it logs the alert and dismisses it
- ************************************************************************************)
- task CheckForAlertOrPositionWindow()
- begin
- if(match[button w:[window ord:1 style:dialog] t:'OK']!)
- begin
- text_messages := collect[staticText w:[window ord:1 style:dialog]]!;
- println "Dismissing dialog that came up after resource type selection -- static text messages follow:";
- for each m in text_messages println " ∂t",m.t;
- select [button t:'OK'];
- end;
- else
- PositionResTypeWindow();
- end;
-
- (************************************************************************************
- * Task CheckForAlertOrPositionWindow2()
- * checks for an alert and if one isn't there positions the window,
- * else it logs the alert and dismisses it. There is an exception for FOND resource
- * ( For ResEdit 2.1 )
- ************************************************************************************)
- task CheckForAlertOrPositionWindow2()
- begin
-
- if(match[ button w:[window o:1 s:dialog ] t:'OK' ]!)
- if( match[ statictext t:/≈Adding a font≈/ ]! )
- Type k:{returnKey,"Chicago",tabKey,"12",returnKey};
- else
- begin
- text_messages := collect[staticText w:[window ord:1 style:dialog]]!;
- println "Dismissing dialog that came up after resource type selection -- static text messages follow:";
- for each m in text_messages println " ∂t",m.t;
- select [button t:'OK'];
- end;
-
- if( match [window t:/≈ID =≈/]! )
- if ( match [window o:1 c:true]! )
- close [window o:1];
- else if( match [menuItem title:'Close' m:'File' e:1 ]! )
- select [menuItem title:'Close' m:'File']!;
-
- if( match [window t:?tText ] and tText <> global gResFileName )
- PositionResTypeWindow();
-
- end;
-
- (************************************************************************************
- * Task CreateOneOfEachType( someOfEach := 0)
- * This task creates one of each resource type if someOfEach is zero.
- * It will create the first ten resource types if someOfEach is 10. etc. ( ResEdit 1.2 )
- ************************************************************************************)
- task CreateOneOfEachType( someOfEach := 0)
- begin
- global gScrollbarLeft,gScrollbarTop;
- global gResFileName;
-
- SetScrollBarGlobals();
- move a:{gScrollbarLeft - 10, gScrollbarTop + 5 };
- click;
- select [button t:'OK']!;
- CheckForAlertOrPositionWindow();
- creationsCount := 1;
-
- while ((global gNonTopItemSelection <> 8) and
- ((not someOfEach) or (creationsCount <> someOfEach)))
- begin
- if(not match[window t:gResFileName o:1]!) select [window t:gResFileName]!;
- select [menuItem title:'New' m:'File']!;
- SelectNextType();
- creationsCount := creationsCount + 1;
- select [button t:'OK']!;
- CheckForAlertOrPositionWindow();
- end;
- end;
-
- (****************************************************************************************************
- * Task CreateOneOfEachType2( someOfEach )
- * This task creates one of each resource type if someOfEach is zero.
- * It will create the first ten resource types if someOfEach is 10. etc.
- ****************************************************************************************************)
- task CreateOneOfEachType2( someOfEach := 0)
- begin
- global gScrollbarLeft,gScrollbarTop;
- global gResFileName;
-
- SetScrollBarGlobals2();
- move a:{ gScrollbarLeft - 10, gScrollbarTop + 5 };
- click;
- select [button t:'OK']!;
- CheckForAlertOrPositionWindow2();
- creationsCount := 1;
-
- while ((global gNonTopItemSelection <> 8) and
- ((not someOfEach) or (creationsCount <> someOfEach)))
- begin
- select [window t:global gResFileName];
- wait(1);
- select [menuItem title:'Create New Resource' m:'Resource']!;
- wait(2);
- SelectNextType();
- creationsCount := creationsCount + 1;
- wait(1);
- select [button t:'OK']!;
- CheckForAlertOrPositionWindow2();
- end;
- end;
-
- (****************************************************************************************************
- * Script ResEditMain(numberOfResourcesToMake)
- * The script parameter numberOfResourcesToMake determines how many resources should
- * be made. Setting it to a value of 0 will cause ResEditTest to create one of each
- * type of resource.
- ****************************************************************************************************)
- script ResEditMain(numberOfResourcesToMake := 0)
- begin
- match [target t:?targetName];
-
- global gResEdit2;
- global gVolumeName;
-
- global gSystem7 := RunningSystemSeven();
- if gSystem7
- println targetName, " Running System 7";
- else
- println targetName, " Not Running System 7";
-
- if gSystem7
- launchOk := LaunchAppInSystem7("ResEdit");
- else
- launchOk := LaunchAppInSystem6("ResEdit");
- if not launchOk
- GracefulExit("ResEdit failed to launch");
-
- wait(2);
- if (match [menu t:"Resource"])
- begin
- gResEdit2 := true;
- println targetName, " Running ResEdit2.1";
- end;
- else
- begin
- gResEdit2 := false;
- println targetName, " Running ResEdit1.2";
- end;
-
- # when gNonTopItemSelection = 7,
- # all types have been created (7 is the number of visible items)
- gNonTopItemSelection := 0;
- gDoneScrolling := false;
- clicksForCurrentValue := 0;
- ## Set this as you like:
- gResFileName := "vu-wants-1-of-each"; # File name to use
-
- SetScreenDependents();
-
- if gResEdit2
- begin
- if ( match[ window t:"" o:1]! and not match[ button ] ) # Splash Screen?
- Select [ Window o:1 ];
-
- CreateResourceFile2(gResFileName);
- CreateOneOfEachType2( numberOfResourcesToMake );
-
- verifString := "window titles follow for verification";
- println "∂n",verifString;
- for i := 1 to (card verifString)
- print "=";
- println;
-
- for each w in collect[window]
- println w.title; # ~~~~~~~~ to verify that all the windows were created
-
- select [menuItem t:'quit'];
- select [button t:"No"];
- end;
- else
- begin
- match [window o:1 t:?gVolumeName]!;
- CreateResourceFile(gResFileName);
- CreateOneOfEachType( numberOfResourcesToMake );
-
- verifString := "window titles follow for verification";
- println "∂n",verifString;
- for i := 1 to card(verifString)
- print "=";
- println;
-
- for each w in collect[window]
- println w.title; # ~~~~~~~~ to verify that all the windows were created
-
- ClearFile(gResFileName,true);
- select [menuItem t:'quit'];
- end;
- end;
-